package  
{
	/**
	 * ...
	 * @author ...
	 */
	public class Snapshot 
	{
		public var x:Number;
		public var y:Number;
		public var rot:Number;
		public var dx:Number;
		public var dy:Number;
		public var c:MovingCircle;
		public function Snapshot(cc:MovingCircle) 
		{
			if (!cc) return;
			c = cc;
			Sync();
		}
		
		public function Sync()
		{
			if (!c) return;
			
			x = c.x;
			y = c.y;
			rot = c.rotation;
			dx = c.dx;
			dy = c.dy;
			if (isNaN(dx))
				throw "NanDX";
		
		}
		
		public function SyncSane()
		{
			if (!c) throw "Non-syncable";
			Sync();
			if (Math.abs(x) < 15)
				throw "Bad X";
		}
		
		public function Apply()
		{
			c.x = x;
			c.y = y;
			c.rotation = rot;
			c.dx = dx;
			c.dy = dy;
		}
		
		public function ClampTo(a:Number, b:Number, c:Number):Number
		{
			b = Math.max(Math.min(a, c), b);
			b = Math.min(Math.max(a, c), b);
			return b;
		}
		
		public function ApplyMix(s:Snapshot, t:Number)
		{
			if (t < 0 || t > 1) throw "Insane t";
			//Linear
			c.x = ClampTo(x,x * (1 - t) + s.x * t,s.x);//Fix calculation errors which affect Sanity
			c.y = ClampTo(y,y * (1 - t) + s.y * t,s.y);//Fix calculation errors which affect Sanity
			c.rotation = rot * (1 - t) + s.rot * t;//TO DO - fix motion to minimum rotation - from 5 to 355 is NOT through 180
			c.dx = dx * (1 - t) + s.dx * t;
			c.dy = dy * (1 -t) + s.dy * t;
			if (Math.abs(c.x) < 15) throw "Bad mix X";
		}
		
		
	}

}